import pygame


class Ultraman:
    def __init__(self, ai_game):

        self.screen = ai_game.screen
        self.screen_rect = ai_game.screen.get_rect()
        # 加载图像并获取其外接矩形
        self.image = pygame.image.load("my_ultra_man/images/ultraman.bmp")
        self.rect = self.image.get_rect()
        # 放在屏幕底部的中央
        self.rect.center = self.screen_rect.center

        self.settings = ai_game.settings

        self.moving_right = False
        self.moving_left = False
        self.moving_up = False
        self.moving_down = False

        self.x = float(self.rect.x)
        self.y = float(self.rect.y)

    def blitme(self):
        self.screen.blit(self.image, self.rect)


    def update(self):
        """根据移动标志调整位置"""
        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.x += self.settings.man_speed

        if self.moving_left and self.rect.left > 0:
            self.x -= self.settings.man_speed

        if self.moving_up and self.rect.top > 0:
            self.y -= self.settings.man_speed

        if self.moving_down and self.rect.bottom < self.screen_rect.bottom:
            self.y += self.settings.man_speed

        
        # rect.x只能是整数，因此需要中间变量x记录x轴坐标的准确数据，用于判断ship是否出界
        self.rect.x = self.x
        self.rect.y = self.y
